package com.ads.tpgrupo4.server.service.ingresarRemitoDeProveedor;

import com.ads.tpgrupo4.domain.cpr.remito.RemitoDeProveedor;
import com.ads.tpgrupo4.server.remote.PersistenceService;
import com.ads.tpgrupo4.server.xml.XmlSource;
import com.ads.tpgrupo4.server.xml.mappers.RemitoDeProveedorXmlMapper;

public class IngresarRemitoDeProveedorService {

	private static IngresarRemitoDeProveedorService instance;

	private PersistenceService persistenceService = PersistenceService
			.getInstance();
	
	private RemitoDeProveedorXmlMapper remitoXmlMapper = RemitoDeProveedorXmlMapper.getInstance();

	public static IngresarRemitoDeProveedorService getInstance() {

		if (instance == null) {
			instance = new IngresarRemitoDeProveedorService();
		}

		return instance;
	}

	private IngresarRemitoDeProveedorService() {
	}
	
	public void ingresarRemitoDeProveedor(final XmlSource remitoDeProveedorXmlSource) {
		
		try {

			final RemitoDeProveedor remito = this.remitoXmlMapper.map(remitoDeProveedorXmlSource);
			
			this.persistenceService.saveRemito(remito);
			
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}		
	}

}
